<html>
<head><meta charset="utf-8"><title>type of const parameters · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html">type of const parameters</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203399143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203399143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203399143">(Jul 09 2020 at 15:18)</a>:</h4>
<p>I wish to explicitly forbid const parameters with generic types.</p>
<p>Why I think supporting them is not worth it for now:</p>



<a name="203399399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203399399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203399399">(Jul 09 2020 at 15:20)</a>:</h4>
<ul>
<li><code>ConstKind::Unevaluated</code> uses its parents generics, meaning that for <code>fn foo&lt;T, const N: [u8; 1 + 2]&gt;()</code> we represent <code>1 + 2</code> as <code>ConstKind::Unevaluated(def, substs = [T, N], promoted = None)</code>.</li>
</ul>



<a name="203399582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203399582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203399582">(Jul 09 2020 at 15:21)</a>:</h4>
<p>This happens because <code>Node::AnonConst</code> use their parents generics, i.e. it currently has the following chain <code>1 + 3</code> -&gt; <code>[u8; _]</code> -&gt; <code>fn foo</code>.</p>



<a name="203399888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203399888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203399888">(Jul 09 2020 at 15:24)</a>:</h4>
<p>As both <code>T</code> and <code>N</code> are taken directly from the generics of <code>fn foo</code>, we can't really keep the current <code>generics_of</code> impl if we want to support generic const param types</p>



<a name="203400569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203400569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203400569">(Jul 09 2020 at 15:28)</a>:</h4>
<ul>
<li>We also have a more difficult version of <a href="https://github.com/rust-lang/rust/pull/74113">https://github.com/rust-lang/rust/pull/74113</a> around type inference here.<br>
i.e. how should we deal with the following examples (at least I believe that this is the case)</li>
</ul>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="nc">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">example1</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Default</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span>::<span class="o">&lt;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="n">T</span>::<span class="n">default</span><span class="p">()}</span><span class="o">&gt;</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Should we infer the type of `T` from the body of `N`?</span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">example2</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span>::<span class="o">&lt;</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="o">&gt;</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="c1">// We probably want to use the type of `T` when type checking `N`.</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203400783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203400783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203400783">(Jul 09 2020 at 15:30)</a>:</h4>
<p>I opened <a href="https://github.com/rust-lang/rust/issues/74152">#74152</a> for this and ended up implementing the first step of that issue in <a href="https://github.com/rust-lang/rust/issues/74159">#74159</a></p>



<a name="203400968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203400968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203400968">(Jul 09 2020 at 15:31)</a>:</h4>
<p>To correctly detect if we are inside of the type of a const param I would do the following:</p>
<ul>
<li>don't simply use the parent item when computing the parent generics by skipping some item kinds<br>
   i.e. instead of <code>1 + 3</code> -&gt; <code>[u8; _]</code> -&gt; <code>fn foo</code> I want <code>1 + 3</code> -&gt; <code>fn foo</code></li>
</ul>



<a name="203401175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203401175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203401175">(Jul 09 2020 at 15:33)</a>:</h4>
<ul>
<li>stop using the parent generics if we are inside of the <code>ty</code> of a <code>GenericParamKind::Const { ty }</code> of the parent (hir) generics</li>
</ul>



<a name="203401356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203401356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203401356">(Jul 09 2020 at 15:34)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> <span class="user-mention" data-user-id="121053">@varkor</span></p>
<ul>
<li>do you want this change?</li>
</ul>



<a name="203401379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203401379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203401379">(Jul 09 2020 at 15:34)</a>:</h4>
<ul>
<li>does my idea on how to implement this seem correct?</li>
</ul>



<a name="203403685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403685">(Jul 09 2020 at 15:52)</a>:</h4>
<p>we're not supposed to allow generic parameters in const param types</p>



<a name="203403709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403709">(Jul 09 2020 at 15:52)</a>:</h4>
<p>this is part of the initial const generics limitations</p>



<a name="203403726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403726">(Jul 09 2020 at 15:52)</a>:</h4>
<p>we do though, which I want to change rn</p>



<a name="203403734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403734">(Jul 09 2020 at 15:52)</a>:</h4>
<p>no that's just a bug</p>



<a name="203403751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403751">(Jul 09 2020 at 15:52)</a>:</h4>
<p>i.e. a missing check</p>



<a name="203403762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403762">(Jul 09 2020 at 15:52)</a>:</h4>
<p>it's not supposed to be allowed</p>



<a name="203403794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403794">(Jul 09 2020 at 15:53)</a>:</h4>
<p>yeah, then I want to implement this check and need feedback <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="203403816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403816">(Jul 09 2020 at 15:53)</a>:</h4>
<p>we'd need traits and whatnot to limit the types to the ones for which const generics are allowed etc.</p>



<a name="203403866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403866">(Jul 09 2020 at 15:53)</a>:</h4>
<p>you can do banning in name resolution</p>



<a name="203403971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403971">(Jul 09 2020 at 15:54)</a>:</h4>
<p>the same way we disallow <code>struct Foo&lt;T = U, U&gt;</code></p>



<a name="203403988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203403988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203403988">(Jul 09 2020 at 15:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203403866">said</a>:</p>
<blockquote>
<p>you can do banning in name resolution</p>
</blockquote>
<p>I already did <a href="https://github.com/rust-lang/rust/pull/74159">https://github.com/rust-lang/rust/pull/74159</a></p>



<a name="203404029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404029">(Jul 09 2020 at 15:54)</a>:</h4>
<p>then you don't need to change anything else?</p>



<a name="203404060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404060">(Jul 09 2020 at 15:54)</a>:</h4>
<p>I do! <code>foo&lt;const N: [u8; 1 + 2]&gt;</code> is broken</p>



<a name="203404081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404081">(Jul 09 2020 at 15:55)</a>:</h4>
<p>because <code>1 + 2</code> contains <code>N</code> in its substs</p>



<a name="203404097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404097">(Jul 09 2020 at 15:55)</a>:</h4>
<p>okay but that's not about anything user-facing</p>



<a name="203404119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404119">(Jul 09 2020 at 15:55)</a>:</h4>
<p>that is, the check and this problem are separate</p>



<a name="203404129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404129">(Jul 09 2020 at 15:55)</a>:</h4>
<p>well, it causes a cycle error</p>



<a name="203404136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404136">(Jul 09 2020 at 15:55)</a>:</h4>
<p>which is fairly userfacing</p>



<a name="203404160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404160">(Jul 09 2020 at 15:55)</a>:</h4>
<p>what I mean is it sounds like you want to add a check to solve this problem</p>



<a name="203404184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404184">(Jul 09 2020 at 15:55)</a>:</h4>
<p>but the check is required by what we agreed to implement as const generics</p>



<a name="203404190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404190">(Jul 09 2020 at 15:55)</a>:</h4>
<p>and separate from this problem</p>



<a name="203404233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404233">(Jul 09 2020 at 15:56)</a>:</h4>
<p>We need to change the way generic parents are handled</p>



<a name="203404246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404246">(Jul 09 2020 at 15:56)</a>:</h4>
<p>sure it's just not related to the check</p>



<a name="203404275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404275">(Jul 09 2020 at 15:56)</a>:</h4>
<p>This is what I need feedback on rn:<br>
<a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203400968">https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203400968</a></p>



<a name="203404311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404311">(Jul 09 2020 at 15:56)</a>:</h4>
<p>like, "I wish to explicitly forbid const parameters with generic types." is uncontroversial, in fact it's required</p>



<a name="203404343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404343">(Jul 09 2020 at 15:57)</a>:</h4>
<p>but that's different from anything to do with <code>generics_of</code></p>



<a name="203404547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404547">(Jul 09 2020 at 15:58)</a>:</h4>
<p>we seem to be talking past each other rn</p>



<a name="203404582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404582">(Jul 09 2020 at 15:58)</a>:</h4>
<p>Let me state my problem step by step so you can intersect where you disagree</p>



<a name="203404626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404626">(Jul 09 2020 at 15:59)</a>:</h4>
<ol>
<li>We want <code>fn foo&lt;const N: [u8; 1 + 2]&gt;</code> to compile</li>
</ol>



<a name="203404638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404638">(Jul 09 2020 at 15:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203400968">said</a>:</p>
<blockquote>
<ul>
<li>don't simply use the parent item when computing the parent generics by skipping some item kinds<br>
   i.e. instead of <code>1 + 3</code> -&gt; <code>[u8; _]</code> -&gt; <code>fn foo</code> I want <code>1 + 3</code> -&gt; <code>fn foo</code></li>
</ul>
</blockquote>
<p>I don't think any change is necessary here</p>



<a name="203404701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404701">(Jul 09 2020 at 15:59)</a>:</h4>
<p>actually I don't even think <code>1 + 3</code> -&gt; <code>[u8; _]</code> -&gt; <code>fn foo</code> happens today</p>



<a name="203404773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404773">(Jul 09 2020 at 16:00)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> yes, but framing that as "forbidding const parameters with generic types" is incorrect IMO</p>



<a name="203404837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404837">(Jul 09 2020 at 16:00)</a>:</h4>
<p>at the start of the topic it sounds like you're talking about about the user writing a generic parameter in the type</p>



<a name="203404865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404865">(Jul 09 2020 at 16:00)</a>:</h4>
<p>whereas this problem is more internal to the implementation</p>



<a name="203404926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203404926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203404926">(Jul 09 2020 at 16:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203404773">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> yes, but framing that as "forbidding const parameters with generic types" is incorrect IMO</p>
</blockquote>
<p>From discussion in const generics issues it seems like you/ <span class="user-mention silent" data-user-id="121053">varkor</span>  wanted to allow this in the future, which is why I explicitly stated this at the start of this discussion</p>



<a name="203405000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405000">(Jul 09 2020 at 16:01)</a>:</h4>
<p>Forbidding generic types is a requirement if  we want to fix the implementation, which is why I mentioned this</p>



<a name="203405004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405004">(Jul 09 2020 at 16:01)</a>:</h4>
<p>we can make it work in the future with some limitations</p>



<a name="203405113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405113">(Jul 09 2020 at 16:02)</a>:</h4>
<p>it's orthogonal to fixing the implementation when the user didn't ask for any generic parameters in the type of the const param</p>



<a name="203405331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405331">(Jul 09 2020 at 16:04)</a>:</h4>
<p>that is, as a future extension, we can try to make it work (or just give up and never do it), but <em>now</em> we can assume it's never the case</p>



<a name="203405457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405457">(Jul 09 2020 at 16:04)</a>:</h4>
<p>similar how today we have associated types without generic parameters but GATs are being/were designed and are being/will be implemented</p>



<a name="203405696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405696">(Jul 09 2020 at 16:06)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> here's a fun exercise: what happens if you have <code>struct Foo&lt;T, U = [u8; 1+2]&gt;(T, U);</code>?</p>



<a name="203405764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405764">(Jul 09 2020 at 16:07)</a>:</h4>
<p>With lazy norm I would expect a cycle error</p>



<a name="203405786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405786">(Jul 09 2020 at 16:07)</a>:</h4>
<p>without lazy norm everything works fine</p>



<a name="203405801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405801">(Jul 09 2020 at 16:07)</a>:</h4>
<p>let me check <span aria-label="sparkles" class="emoji emoji-2728" role="img" title="sparkles">:sparkles:</span></p>



<a name="203405983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203405983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203405983">(Jul 09 2020 at 16:08)</a>:</h4>
<p>oh oops I'm not making it use parent generics lol</p>



<a name="203406016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406016">(Jul 09 2020 at 16:08)</a>:</h4>
<p>yeah it ICEs lol</p>



<a name="203406024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406024">(Jul 09 2020 at 16:09)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="n">error</span>: <span class="nc">internal</span><span class="w"> </span><span class="n">compiler</span><span class="w"> </span><span class="n">error</span>: <span class="nc">src</span><span class="o">/</span><span class="n">librustc_middle</span><span class="o">/</span><span class="n">ty</span><span class="o">/</span><span class="n">subst</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">554</span>:<span class="mi">17</span>: <span class="nc">type</span><span class="w"> </span><span class="n">parameter</span><span class="w"> </span><span class="err">`</span><span class="n">U</span><span class="o">/</span><span class="err">#</span><span class="mi">1</span><span class="err">`</span><span class="w"> </span><span class="p">(</span><span class="n">U</span><span class="o">/</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="n">out</span><span class="w"> </span><span class="n">of</span><span class="w"> </span><span class="n">range</span><span class="w"> </span><span class="n">when</span><span class="w"> </span><span class="n">substituting</span><span class="w"> </span><span class="p">(</span><span class="n">root</span><span class="w"> </span><span class="k">type</span><span class="o">=</span><span class="nb">Some</span><span class="p">([</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">_</span><span class="p">]))</span><span class="w"> </span><span class="n">substs</span><span class="o">=</span><span class="p">[</span><span class="kt">u8</span><span class="p">]</span><span class="w"></span>
<span class="w"> </span><span class="o">-</span>-&gt; <span class="nc">src</span><span class="o">/</span><span class="n">main</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">6</span>:<span class="mi">12</span><span class="w"></span>
<span class="w">  </span><span class="o">|</span><span class="w"></span>
<span class="mi">6</span><span class="w"> </span><span class="o">|</span><span class="w">     </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="o">|</span><span class="w">            </span><span class="o">^^^^^^</span><span class="w"></span>
</code></pre></div>



<a name="203406097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406097">(Jul 09 2020 at 16:09)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=fe719231d2c620d6bf56fa8858040d84">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=fe719231d2c620d6bf56fa8858040d84</a></p>



<a name="203406107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406107">(Jul 09 2020 at 16:09)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(const_generics)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>
<span class="k">type</span> <span class="nc">Bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="203406196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406196">(Jul 09 2020 at 16:10)</a>:</h4>
<p>that's, IMO, the same bug</p>



<a name="203406201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406201">(Jul 09 2020 at 16:10)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(const_generics)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">U</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">U</span><span class="p">);</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nc">Foo</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203406259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406259">(Jul 09 2020 at 16:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203406196">said</a>:</p>
<blockquote>
<p>that's, IMO, the same bug</p>
</blockquote>
<p>I think so too, which I want to fix by not supplying <code>T, U</code> to <code>1 + 2</code></p>



<a name="203406304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406304">(Jul 09 2020 at 16:11)</a>:</h4>
<p>yes, anything inside the definition of generic parameters shouldn't see those generic parameters in scope</p>



<a name="203406381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406381">(Jul 09 2020 at 16:11)</a>:</h4>
<p>Though, what about <code>Foo&lt;T, U = [u8; std::mem::size_of&lt;T&gt;]&gt;</code></p>



<a name="203406395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406395">(Jul 09 2020 at 16:11)</a>:</h4>
<p>exactly, I was gonna bring that up</p>



<a name="203406411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406411">(Jul 09 2020 at 16:11)</a>:</h4>
<p>I think we should disallow this in name resolution</p>



<a name="203406464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406464">(Jul 09 2020 at 16:12)</a>:</h4>
<p>as "unimplementable for now"</p>



<a name="203406561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406561">(Jul 09 2020 at 16:12)</a>:</h4>
<p>So the limitation is: We are inside of a const context + inside of a generic param ty/default =&gt; forbid generic params</p>



<a name="203406598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406598">(Jul 09 2020 at 16:13)</a>:</h4>
<p>I think so yeah</p>



<a name="203406633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406633">(Jul 09 2020 at 16:13)</a>:</h4>
<p>nice <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="203406654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406654">(Jul 09 2020 at 16:13)</a>:</h4>
<p>Now back to <code>ty::Generics</code></p>



<a name="203406659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406659">(Jul 09 2020 at 16:13)</a>:</h4>
<p>not all generic params though, just those from the same list of params as what this is in</p>



<a name="203406689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406689">(Jul 09 2020 at 16:13)</a>:</h4>
<p>(think method using params of impl)</p>



<a name="203406738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406738">(Jul 09 2020 at 16:14)</a>:</h4>
<p>wait no nvm that's still broken, isn't it?</p>



<a name="203406789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406789">(Jul 09 2020 at 16:14)</a>:</h4>
<p>i think that's fine if we do it right</p>



<a name="203406807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406807">(Jul 09 2020 at 16:14)</a>:</h4>
<p>let me quickly write an example of what I mean here</p>



<a name="203406818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406818">(Jul 09 2020 at 16:14)</a>:</h4>
<p>I guess it wouldn't ICE exactly as these examples do</p>



<a name="203406855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406855">(Jul 09 2020 at 16:15)</a>:</h4>
<p>since the parent substitutions would entirely exist</p>



<a name="203406876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406876">(Jul 09 2020 at 16:15)</a>:</h4>
<p>and <code>ty::Generics</code> can represent that case</p>



<a name="203406888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406888">(Jul 09 2020 at 16:15)</a>:</h4>
<p>what <code>ty::Generics</code> can't represent today is subsets</p>



<a name="203406906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203406906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203406906">(Jul 09 2020 at 16:15)</a>:</h4>
<p>hopefully maybe that will improve with Chalk</p>



<a name="203407013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407013">(Jul 09 2020 at 16:16)</a>:</h4>
<p>This already works I guess</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#![feature(const_generics)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203407040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407040">(Jul 09 2020 at 16:16)</a>:</h4>
<p>heh</p>



<a name="203407110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407110">(Jul 09 2020 at 16:17)</a>:</h4>
<p>although <code>N</code> in the array length isn't an unevaluated expression</p>



<a name="203407139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407139">(Jul 09 2020 at 16:17)</a>:</h4>
<p>yeah, <code>ConstKind::Unevaluated</code> currently always breaks</p>



<a name="203407161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407161">(Jul 09 2020 at 16:18)</a>:</h4>
<p>because it contains ALL THE SUBSTS</p>



<a name="203407271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407271">(Jul 09 2020 at 16:18)</a>:</h4>
<p>okay so for <code>generics_of</code>: you can walk the nodes up through types until you find the generic param node - although I'm not 100% sure the type is a child of the generic param?</p>



<a name="203407279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407279">(Jul 09 2020 at 16:18)</a>:</h4>
<p>I guess I can find out</p>



<a name="203407360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407360">(Jul 09 2020 at 16:19)</a>:</h4>
<p>awww <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_middle/hir/map/collector.rs#L360-L363">https://github.com/rust-lang/rust/blob/master/src/librustc_middle/hir/map/collector.rs#L360-L363</a></p>



<a name="203407410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407410">(Jul 09 2020 at 16:19)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> the walk call there should look like this: <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_middle/hir/map/collector.rs#L424-L426">https://github.com/rust-lang/rust/blob/master/src/librustc_middle/hir/map/collector.rs#L424-L426</a></p>



<a name="203407466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203407466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203407466">(Jul 09 2020 at 16:20)</a>:</h4>
<p>then you should be able to find the node just by walking up the HIR</p>



<a name="203410311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203410311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203410311">(Jul 09 2020 at 16:42)</a>:</h4>
<p>will have to look at this, kind of afraid of something like this breaking because of this :/</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">struct</span> <span class="nc">Value</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">M</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">           </span><span class="c1">// ...</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="mi">7</span><span class="w"></span>
<span class="p">}]</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="203427377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203427377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203427377">(Jul 09 2020 at 19:16)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> well you'd stop at an item node, at the very least</p>



<a name="203427418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203427418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203427418">(Jul 09 2020 at 19:17)</a>:</h4>
<p><code>struct</code> and <code>impl</code> will continue to have no generics parent</p>



<a name="203427470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203427470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203427470">(Jul 09 2020 at 19:17)</a>:</h4>
<p>and anything inside them would never go beyond them</p>



<a name="203437192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203437192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203437192">(Jul 09 2020 at 20:38)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/74159">https://github.com/rust-lang/rust/pull/74159</a> now works, even if I fear that it is somewhat inefficient <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="203438960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203438960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203438960">(Jul 09 2020 at 20:52)</a>:</h4>
<p>Well, structs in the type of const params ICE for completely different reasons <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span> why is this all such a damn mess</p>
<p><a href="https://github.com/rust-lang/rust/issues/74199">https://github.com/rust-lang/rust/issues/74199</a></p>



<a name="203613215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203613215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203613215">(Jul 11 2020 at 21:00)</a>:</h4>
<p>Sorry, this week has been very busy with deadlines.</p>



<a name="203613224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203613224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203613224">(Jul 11 2020 at 21:00)</a>:</h4>
<p>I don't understand where the original check went: this should have already been forbidden. It must have accidentally been removed, but I'm not sure how.</p>



<a name="203613231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203613231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203613231">(Jul 11 2020 at 21:00)</a>:</h4>
<p>Also, <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> did not want this sort of check in name resolution. It should be in the same place that does <code>structural_match</code> checking.</p>



<a name="203613237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203613237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203613237">(Jul 11 2020 at 21:01)</a>:</h4>
<p>Maybe it got messed up when all the <code>structural_match</code> refactoring was going on?</p>



<a name="203618517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618517">(Jul 11 2020 at 23:38)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> wait what does any of this have to do with <code>structural_match</code>?</p>



<a name="203618522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618522">(Jul 11 2020 at 23:39)</a>:</h4>
<p>it needs to be in name resolution because you can't avoid ICE-ing if it does resolve</p>



<a name="203618624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618624">(Jul 11 2020 at 23:42)</a>:</h4>
<p>this is the same reason why we handle <code>struct Foo&lt;T = T&gt;</code> in name resolution</p>



<a name="203618629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618629">(Jul 11 2020 at 23:42)</a>:</h4>
<p>we can do both later, and it might a good idea to do that, but we'd have to augment <code>AstConv</code> with "generic parameters in scope"</p>



<a name="203618632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618632">(Jul 11 2020 at 23:43)</a>:</h4>
<p>currently we just trust name resolution</p>



<a name="203618678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618678">(Jul 11 2020 at 23:44)</a>:</h4>
<p>I thought what we were doing previously was checking whether a type was structural_match to decide whether to allow it. Types with generic parameters were forbidden as part of that check.</p>



<a name="203618679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618679">(Jul 11 2020 at 23:44)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> so to explain a bit, you can't allow creating a <code>ty::Param(...)</code> (in <code>rustc_typeck::astconv</code>) that refers to a type parameter that is not going to be available for substitution later, as it will ICE. so if we want to prevent that in <code>rustc_typeck</code> we have to perfectly model "type parameters in scope" instead of relying on <code>rustc_resolve</code>'s (more direct) understanding</p>



<a name="203618684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618684">(Jul 11 2020 at 23:45)</a>:</h4>
<p>I may be misremembering though.</p>



<a name="203618689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618689">(Jul 11 2020 at 23:45)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span> that doesn't prevent the type from existing</p>



<a name="203618692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618692">(Jul 11 2020 at 23:45)</a>:</h4>
<p>and ICE-ing anything it touches</p>



<a name="203618693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618693">(Jul 11 2020 at 23:45)</a>:</h4>
<p>Right.</p>



<a name="203618748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618748">(Jul 11 2020 at 23:46)</a>:</h4>
<p>so one of two places needs to block this, and IMO if we switch to <code>rustc_typeck</code> we should move the thing about type parameter defaults there too</p>



<a name="203618751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618751">(Jul 11 2020 at 23:46)</a>:</h4>
<p>since we'd have the information to disallow it there and it would be cleaner than the hack in <code>rustc_resolve</code></p>



<a name="203618753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618753">(Jul 11 2020 at 23:47)</a>:</h4>
<p>That does seem like the most natural place, but would require some refactoring, so probably sticking it in resolve is best for now.</p>



<a name="203618756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618756">(Jul 11 2020 at 23:47)</a>:</h4>
<p>it's just... work. and it might be easy to get wrong "generic parameters in scope", not sure (it might just as well be straight-forward)</p>



<a name="203618760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618760">(Jul 11 2020 at 23:47)</a>:</h4>
<p>right. and to be clear, AFAICT I'd welcome the refactor</p>



<a name="203618763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618763">(Jul 11 2020 at 23:47)</a>:</h4>
<p>Agreed.</p>



<a name="203618765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618765">(Jul 11 2020 at 23:47)</a>:</h4>
<p>maybe I should've tried it a while back (read: many years ago) to deal with the ICEs from the broken <code>generics_of</code> for constant expressions</p>



<a name="203618803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618803">(Jul 11 2020 at 23:48)</a>:</h4>
<p>Unfortunately I don't have much time to write code at the moment :(</p>



<a name="203618804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618804">(Jul 11 2020 at 23:48)</a>:</h4>
<p>working on <code>rustc</code> is a recipe for accumulating a lifetime of regrets,,,</p>



<a name="203618807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618807">(Jul 11 2020 at 23:48)</a>:</h4>
<p>:P</p>



<a name="203618821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618821">(Jul 11 2020 at 23:49)</a>:</h4>
<p>It continues to get better, little by little, refactor by refactor.</p>



<a name="203618875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203618875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203618875">(Jul 11 2020 at 23:50)</a>:</h4>
<p>I guess for now we can open up a C-cleanup issue to keep a record of this somewhere.</p>



<a name="203636022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203636022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203636022">(Jul 12 2020 at 09:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203618821">said</a>:</p>
<blockquote>
<p>It continues to get better, little by little, refactor by refactor.</p>
</blockquote>
<p>If only people who like to accumulate technical debt weren't much more productive than those who like cleaning it up...</p>



<a name="203636133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203636133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203636133">(Jul 12 2020 at 09:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203618679">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <span class="user-mention silent" data-user-id="123856">Vadim Petrochenkov</span> so to explain a bit, you can't allow creating a <code>ty::Param(...)</code> (in <code>rustc_typeck::astconv</code>) that refers to a type parameter that is not going to be available for substitution later, as it will ICE</p>
</blockquote>
<p>I see.<br>
It should be some generic check for type parameters than are "not in scope in typeck sense", if it's done in resolve.<br>
The last time I've seen it implemented it was a very special case for const generics.</p>



<a name="203636190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203636190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203636190">(Jul 12 2020 at 09:41)</a>:</h4>
<p>Without these peculiarities with ICEs from substs, a generic parameter is just one of many kinds of non structurally-comparable types, so I suggested to unify these checks.</p>



<a name="203660240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203660240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203660240">(Jul 12 2020 at 20:45)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> arguably, yes, but that (checking it in the "is structural match" logic) only works if the generic parameter is actually "in scope" (and we could allow it if we just had something like a <code>T: StructuralMatch</code> bound the user could use), which is sadly not the case</p>



<a name="203660319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203660319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203660319">(Jul 12 2020 at 20:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123856">Vadim Petrochenkov</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203636133">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/131828-t-compiler/topic/type.20of.20const.20parameters/near/203618679">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <span class="user-mention silent" data-user-id="123856">Vadim Petrochenkov</span> so to explain a bit, you can't allow creating a <code>ty::Param(...)</code> (in <code>rustc_typeck::astconv</code>) that refers to a type parameter that is not going to be available for substitution later, as it will ICE</p>
</blockquote>
<p>I see.<br>
It should be some generic check for type parameters than are "not in scope in typeck sense", if it's done in resolve.<br>
The last time I've seen it implemented it was a very special case for const generics.</p>
</blockquote>
<p>fair, although the "type parameter defaults only seeing type parameters before, not after" rule is weirdly specific and complicates things</p>



<a name="203660369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/type%20of%20const%20parameters/near/203660369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/type.20of.20const.20parameters.html#203660369">(Jul 12 2020 at 20:48)</a>:</h4>
<p>also the difference between "type param default / const param type (or default if we add those)" and bounds makes it ugly, since bounds don't have any restrictions</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>